﻿toggle = function (fsid)
{
    var div = $id("div_" + fsid);
    var btnCancel = $id("btnCancel_" + fsid);
    var btnSave = $id("btnSave_" + fsid);
    var load = $id("load_" + fsid);
        
    var display = "";
    
    if( div.style.display != "none" )
    {
        display = "none";
    }
    
    div.style.display = display;
    if(btnCancel != null && btnSave != null)
    {
        btnCancel.style.display = display;
        btnSave.style.display = display;
        load.style.display = display;
    }
    //btn.style.display = display;
    
}
EditPlannedDate = function(cvid)
{
    var div = $id("popuplayer");    div.style.display = "block";    div.innerHTML = "<img src='" + LOADING.src + "' alt='' />";    renderFirst();        cbkList_c.PerformCallback("EDIT" + DELIMITER + cvid); 
}
cbkList_c_CallbackComplete = function(e){
    if( e.parameter.startsWith("EDIT") )
    {
        var div = $id("popuplayer");
        div.innerHTML = e.result;    }
    else if( e.parameter.startsWith("SAVE"))
    {
        closeEditPlannedDate();
        dgVisitView_c.PerformCallback("REFRESH");
    }
}
dgVisitView_c_CallbackComplete = function(e){
    //if(e.parameter.startsWith("CANCEL"))
    //{
    //    dgVisitView_c.PerformCallback("REFRESH");
    //}
}
closeEditPlannedDate = function(){
    var div = $id("popuplayer");    div.innerHTML = "";    div.style.display = "none";
}
saveEditPlannedDate = function(iCVID)
{
    var load = $id("load");
    //var btn = $id("btn_CCNew");
    if(confirm("save changes?"))
    {
        //alert(iCCID);
        // di sini kirim data perubahannya
        var input = getData(iCVID);
        alert (input);
        //btn.style.display = "none";
        load.innerHTML = "<img src='" + LOADING.src + "' alt='' />"; 
        cbkList_c.PerformCallback(input);
    }
}
getData = function(iCVID)
{
    var inputs = $id("CV.VISITDATETIME");
    var output = "SAVE" + DELIMITER +iCVID + DELIMITER + inputs.value;
    return output;
}
DoCancel = function(iCVID)
{
    var reason = $id("reasonEditor");
    if(confirm("Cancel Plan?"))
    {
        dgVisitView_c.PerformCallback("CANCEL" + DELIMITER + iCVID + DELIMITER + reason.value);
    } 
}
/*add by rista*/
ShowAll1 = function()
{
    $id("CV.START").value = "";
    $id("CV.END").value = "";
    dgVisitView_c.PerformCallback("ALL");
}
Filter1 = function()
{
    var START = $id("CV.START").value;
    var END = $id("CV.END").value;
    
    if ($id("CV.START").value == '' || $id("CV.END").value == '')
    {
        alert('Silahkan mengisi periode awal dan akhir.');
    }
    else {
        //alert('start date: ' + START + 'end date: ' + END);
        var months = new Array ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');

        var startDay, endDay, startMonth, endMonth, startYear, endYear;
        
        startDay = START.split('-')[0];
        endDay = END.split('-')[0];
        startMonth = START.split('-')[1];
        endMonth = END.split('-')[1];
        startYear = START.split('-')[2];
        endYear = END.split('-')[2];
        
        for (i = 0 ; i < months.length ; i++)
        {
            if (startMonth == months[i])
            {
                startMonth = i + 1;
                break;
            }
        }
        for (i = 0 ; i < months.length ; i++)
        {
            if (endMonth == months[i])
            {
                endMonth = i + 1;
                break;
            }
        }
        
        if (new Date(startYear, startMonth, startDay) > new Date(endYear, endMonth, endDay))
        {
            alert('Tanggal awal harus lebih kecil dari tanggal akhir.');
        }
        else
        {
            dgVisitView_c.PerformCallback("FILTER"+DELIMITER+START+DELIMITER+END);
        }
        //dgVisitView_c.PerformCallback("FILTER"+DELIMITER+START+DELIMITER+END);
    }
}